class Solution
{
public:
    int maximumLengthSubstring(string s)
    {
        int n = s.size();
        int result = 0;
        for (int i = 0; i < n; ++i)
        {
            for (int j = i; j < n; ++j)
            {
                vector<int> count(26, 0);
                for (int k = i; k <= j; ++k)
                {
                    count[s[k] - 'a']++;
                }
                if (*max_element(count.begin(), count.end()) <= 2)
                {
                    result = max(result, j - i + 1);
                }
            }
        }
        return result;
    }
};